﻿using System;

namespace Eswat
{
	/// <summary>
	/// Test runner result.
	/// </summary>
	/// <typeparam name="TTestTarget">The type of the test target.</typeparam>
	/// <typeparam name="TResult">The type of the result.</typeparam>
	public class TestRunnerResult<TResult, TTestTarget> : ITestRunnerResult<TResult, TTestTarget>
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="TestRunnerResult&lt;TTestTarget, TResult&gt;"/> class.
		/// </summary>
		/// <param name="result">The result.</param>
		/// <param name="testContext">The test context.</param>
		public TestRunnerResult(
			TResult result,
			ITestContext<TTestTarget> testContext)
		{
			this.Result = result;
			this.TestContext = testContext;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TestRunnerResult&lt;TTestTarget, TResult&gt;"/> class.
		/// </summary>
		/// <param name="exception">The exception.</param>
		/// <param name="testContext">The test context.</param>
		public TestRunnerResult(
			Exception exception,
			ITestContext<TTestTarget> testContext)
		{
			this.InnerException = exception;
			this.TestContext = testContext;
		}

		/// <summary>
		/// Gets the test result.
		/// </summary>
		public TResult Result { get; private set; }

		/// <summary>
		/// Gets the test context.
		/// </summary>
		public ITestContext<TTestTarget> TestContext { get; private set; }

		/// <summary>
		/// Gets the inner exception.
		/// </summary>
		public Exception InnerException { get; private set; }

		/// <summary>
		/// Gets a value indicating whether this instance is error.
		/// </summary>
		/// <value>
		///   <c>true</c> if this instance is error; otherwise, <c>false</c>.
		/// </value>
		public bool IsError { get { return this.InnerException != null; } }
	}
}
